package com.tpshion.chat.service.impl;

import com.tpshion.chat.domain.entity.Friend;
import com.tpshion.chat.domain.vo.FriendsVo;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.tpshion.chat.mapper.FriendMapper;
import com.tpshion.chat.service.FriendService;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

@Service
public class FriendServiceImpl implements FriendService{

    @Resource
    private FriendMapper friendMapper;

    /**
     * 根据用户id获取好友列表
     * @param userId
     * @return
     */
    @Override
    public List<FriendsVo> getListByUserId(String userId) {
        return friendMapper.getListByUserId(userId);
    }

    /**
     * 检查是否为好友
     * @param userId
     * @param friendId
     * @return
     */
    @Override
    public Friend checkFriend(String userId, String friendId) {

        return friendMapper.checkFriend(userId,friendId);
    }

    /**
     * 添加好友
     * @param friend
     */
    @Override
    @Transactional
    public void addFriend(Friend friend) {
        friendMapper.insertSelective(friend);
    }
}
